package com.mz.ozy.widget.dialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.activity.assets.RechargeActivity;
import com.mz.ozy.activity.me.PayPwdActivity;

public class ConfirmPayDialog extends BaseDialog implements View.OnClickListener {

    private EditText mEtDescribeMsg;
    private TextView mTvGoodsPrice;
    private TextView mTvBalance;
    private String ktbalance;
    private String price;
    private String xfbalance;
    private int priceType;

    public ConfirmPayDialog(Activity mContext) {
        super(mContext, R.layout.dialog_coach_comment, Gravity.CENTER, true, true);
        initView();
    }

    private void initView() {
        setOnViewClick(R.id.tv_cancel, this);
        setOnViewClick(R.id.tv_submit, this);
        setOnViewClick(R.id.tv_kt_pay, this);
        setOnViewClick(R.id.tv_forget_pass, this);
        mEtDescribeMsg = getView(R.id.et_describe_msg);
        mTvGoodsPrice = getView(R.id.tv_goods_price);
        mTvBalance = getView(R.id.tv_balance);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cancel:
                if (mListener != null) {
                    mListener.onCancel();
                }
                break;
            case R.id.tv_submit:
                if (mListener != null) {
                    String msg = mEtDescribeMsg.getText().toString().trim();
                    mListener.onSubmit(msg);
                }
                break;
            case R.id.tv_kt_pay:
                RechargeActivity.go(mContext, 0, false, "");
                toggleDialog();
                break;
            case R.id.tv_forget_pass:
                mContext.startActivity(new Intent(mContext, PayPwdActivity.class));
//                toggleDialog();
                break;
        }
    }

    private onDialogListener mListener;

    public void setOnDialogListener(onDialogListener listener) {
        mListener = listener;
    }

    public void setBalance(String ktbalance, String xfbalance, String price, int priceType) {
        this.ktbalance = ktbalance;
        this.xfbalance = xfbalance;
        this.price = price;
        this.priceType = priceType;
        setViewData();
    }

    private void setViewData() {
        if (priceType == 0) {
            mTvBalance.setText("通证余额:" + getPrice(ktbalance));
        } else if (priceType == 1) {
            mTvBalance.setText("消费积分余额:" + getPrice(xfbalance));
        } else {
            mTvBalance.setText("通证余额:" + getPrice(ktbalance) + " 消费积分余额:" + getPrice(xfbalance));
        }
        if (!TextUtils.isEmpty(price)) {
            mTvGoodsPrice.setText(price);
        }
    }

    private String getPrice(String price) {
        if (TextUtils.isEmpty(price)) {
            return "0.00";
        }
        return price;
    }

    public interface onDialogListener {
        void onCancel();

        void onSubmit(String id);
    }
}
